<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="${ctx }/resources/lib/html5.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/respond.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/PIE_IE678.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="${ctx }/resources/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="${ctx }/resources/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="${ctx }/resources/lib/Hui-iconfont/1.0.7/iconfont.css" />
<link rel="stylesheet" type="text/css" href="${ctx }/resources/lib/icheck/icheck.css" />
<link rel="stylesheet" type="text/css" href="${ctx }/resources/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="${ctx }/resources/css/style.css" />
<link rel="stylesheet" type="text/css" href="${ctx }/resources/lib/bootstrap/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="${ctx }/resources/fonts/fontawesome/font-awesome.min.css" media="all"/>
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="${ctx }/resources/lib/dtGrid-v1.1.9/jquery.dtGrid.css" />
<title>角色列表</title>
</head>
<body>
<div class="page-container">
	<div class="text-c"> 日期范围：
		<input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'createTimeStart\')||\'%y-%M-%d\'}'})" id="createTimeStart" class="input-text Wdate" style="width:120px;">
		-
		<input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'createTimeEnd\')}',maxDate:'%y-%M-%d'})" id="createTimeEnd" class="input-text Wdate" style="width:120px;">
		<input type="text" name="searchKey" id="searchKey" placeholder=" 关键字" style="width:250px" class="input-text">
		<button name="searchBtn" id="searchBtn" class="btn btn-success" onclick="searchRows()"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		<span class="l">
			<a href="javascript:;" onclick="deleteRows()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 删除</a> 
			<a class="btn btn-primary radius" onclick="addRow('添加角色','${ctx}/role/add')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加</a>
		</span> 
	</div>
	<div class="mt-20">
		<div id="dtGridContainer" class="dt-grid-container"></div>
		<div id="dtGridToolBarContainer" class="dt-grid-toolbar-container"></div>
	</div>
</div>
<script type="text/javascript" src="${ctx }/resources/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${ctx }/resources/lib/bootstrap/bootstrap.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/layer/2.1/layer.js"></script> 
<script type="text/javascript" src="${ctx }/resources/lib/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="${ctx }/resources/js/H-ui.js"></script> 
<script type="text/javascript" src="${ctx }/resources/js/H-ui.admin.js"></script> 
<script type="text/javascript" src="${ctx }/resources/lib/dtGrid-v1.1.9/jquery.dtGrid.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/dtGrid-v1.1.9/i18n/zh-cn.js"></script>
<script type="text/javascript" src="${ctx }/resources/ams/util/util.js"></script>
<script type="text/javascript">
var ctx = '${ctx}';
var columns = [{
    id : 'roleId',
    title : '编号',
    type : 'number',
    hideType : 'xs',
    headerStyle : 'background:#00a2ca;color:white;'
}, {
    id : 'roleName',
    title : '角色名',
    type : 'string',
    headerStyle : 'background:#00a2ca;color:white;'
}, {
    id : 'roleCode',
    title : '标识',
    type : 'string',
    headerStyle : 'background:#00a2ca;color:white;'
}, {
    id : 'status',
    title : '状态',
    type : 'string',
    headerStyle : 'background:#00a2ca;color:white;',
    hideType : 'sm|xs',
    resolution : function(value, record, column, grid, dataNo, columnNo) {
        if (value == 0) {
            return '<span class="label label-sm label-success arrowed arrowed-righ">正常</span>';
        } else {
            return '<span class="label label-sm label-warning arrowed arrowed-righ">异常</span>';
        }
    }
}, {
    id : 'description',
    title : '描述',
    type : 'string',
    headerStyle : 'background:#00a2ca;color:white;',
    hideType : 'sm|xs'
}, {
    id : 'createTime',
    title : '创建时间',
    type : 'date',
    format : 'yyyy-MM-dd hh:mm:ss',
    otype : 'string',
    oformat : 'yyyy-MM-dd hh:mm:ss',
    columnClass : 'text-center',
    headerStyle : 'background:#00a2ca;color:white;',
    hideType : 'sm|xs'
}, {
    id : 'updateTime',
    title : '更新时间',
    type : 'date',
    format : 'yyyy-MM-dd hh:mm:ss',
    otype : 'string',
    oformat : 'yyyy-MM-dd hh:mm:ss',
    headerStyle : 'background:#00a2ca;color:white;',
    hideType : 'sm|xs|md',
    resolution : function(value, record, column, grid, dataNo, columnNo) {
        if (value == null) {
            return '';
        } else {
            return value;
        }
    }
}, {
	id : 'operation',
    title : '操作',
    type : 'string',
    headerStyle : 'background:#00a2ca;color:white;',
    resolution : function(value, record, column, grid, dataNo, columnNo) {
    	return '<a style="text-decoration:none" class="ml-5" onClick="editRow('+record.roleId+')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>';
    }
}];

var grid = $.fn.DtGrid.init({
    lang : 'zh-cn',
    ajaxLoad : true,
    check : true,
    loadURL : ctx + '/role/list',
    columns : columns,
    gridContainer : 'dtGridContainer',
    toolbarContainer : 'dtGridToolBarContainer',
    tools : '',
    pageSize : 10,
    pageSizeLimit : [10, 20, 30]
});

$(function(){
	grid.load();
});

function searchRows(){
	grid.parameters = new Object();
	grid.parameters['searchValue'] = $("#searchKey").val();
	grid.parameters['createTimeStart'] = $("#createTimeStart").val();
	grid.parameters['createTimeEnd'] = $("#createTimeEnd").val();
    grid.refresh(true);
}

function deleteRows(){
	var records = grid.getCheckedRecords();
	if(0 >= records.length){
		layer.msg('请先选择要删除的数据!',{icon: 5,time:1000});
	} else {
		layer.confirm('确认要删除吗？',function(index){
			var ids = ams.util.getCheckedIds(records, 'roleId');
			$.post('${ctx}/role/delete', {ids : ids}, function(result){
				if(ams.util.ajaxAuthResult(result)){
					if(result){
						searchRows();
						layer.msg('已删除!',{icon:1,time:1000});
					} else {
						searchRows();
						layer.msg('删除失败!',{icon:5,time:1000});
					}
				}
			});
		});
	}
}

function addRow(title,url){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}

function editRow(roleId){
	var url = ctx + '/role/'+roleId+'/edit';
	addRow('编辑角色', url);
}
</script>
</body>
</html>